<?php
$type = isset($_GET['type']) ? intval($_GET['type']) : 0;
$orderby = get_major_key(array('rank' => 'DESC', 'id' => 'ASC'));

$oPrototype = new Prototype();

if(!empty($_GET['btnExport'])){	// 导出
	$list = $oPrototype->get_list('*', $_GET, $orderby, 1, 65536, $offset = 0);
	if(!empty($list['list']) && is_array($list['list'])){
		$data = array();
		foreach($list['list'] as $row){
			$row['value'] 	= $oPrototype->format_value_out($row['type'], $row['value']);
			$row['type']	= Statics::$prototype_type_arr[$row['type']];
			$row['time'] 	= utime($row['addtime'], $row['updatetime']);
			$data[] = $row;
		}
		$headers = array(
			'id'		=> array('title' => 'ID',		'width' => '6'),
			'name'		=> array('title' => '名称', 	'width' => '12.5'),
			'type'		=> array('title' => '类型', 	'width' => '8'),
			'value'		=> array('title' => '值', 		'width' => '50', 'wrap' => true),
			'prompt'	=> array('title' => '提示', 	'width' => '25', 'wrap' => true),
			'regexp'	=> array('title' => '正则限制', 'width' => '25'),
			'time'		=> array('title' => '时间', 	'width' => '18'),
		);
		if($list['total'] > 5000){	// 导出超过5000时用CSV
			export_csv($data, $headers, '_E_原型_'.date('Ymd_His').'.csv');
		}else{
			$oExcel = new Excel();
			$oExcel->export($headers, $data, '_E_原型_'.date('Ymd_His').'.xlsx');
		}
	}
	exit;
}

$list = $oPrototype->get_list('*', $_GET, $orderby, $__page, $__pagesize);
if(!empty($list['list']) && is_array($list['list'])){
	// 主键排序字段
	make_major_key_options(array(
		'id'		=> '添加时间',
		'rank'		=> '排序号',
	));

	foreach($list['list'] as $key => $row){
		$row['value'] 		= $oPrototype->format_value_out($row['type'], $row['value']);
		$row['type']		= Statics::$prototype_type_arr[$row['type']];
		$row['addtime'] 	= ftime($row['addtime']);
		$row['updatetime']	= ftime($row['updatetime']);
		$list['list'][$key] = $row;
	}
	$vars['list'] = $list['list'];
	$vars['pagelist'] = $list['pagelist'];
}

// 保持搜索参数
$vars['type_options'] = make_options(Statics::$prototype_type_arr, true, $type);
?>